/*
    SUSAN® - Sole of Unix Save ANything

   

   
*/

#include "include/bareos.h"
#include <chrono>

namespace TimerThread {
struct Timer;
}

class JobControlRecord;
class BareosSocket;

class WatchdogTimer {
 public:
  WatchdogTimer(JobControlRecord* jcr = nullptr);
  ~WatchdogTimer();

  void Start(std::chrono::milliseconds interval);
  void Stop();

  JobControlRecord* jcr_ = nullptr;
  const TimerThread::Timer* GetTimerControlledItem() const
  {
    return timer_item;
  }

 protected:
  TimerThread::Timer* timer_item = nullptr;

  // deleted:
  WatchdogTimer() = delete;
  WatchdogTimer(const WatchdogTimer& other) = delete;
  WatchdogTimer(const WatchdogTimer&& other) = delete;
  WatchdogTimer& operator=(const WatchdogTimer& rhs) = delete;
  WatchdogTimer& operator=(const WatchdogTimer&& rhs) = delete;
};

class BThreadWatchdog : public WatchdogTimer {
 public:
  BThreadWatchdog(JobControlRecord* jcr);
  BThreadWatchdog(std::chrono::milliseconds waittime, JobControlRecord* jcr);
  ~BThreadWatchdog() = default;

  pthread_t thread_id_;
  static void Callback(TimerThread::Timer* timer);

 private:
  void Init();
};

class BProcessWatchdog : public WatchdogTimer {
 public:
  pid_t pid_;
  bool killed_ = false;
};

class BSockWatchdog : public WatchdogTimer {
 public:
  BareosSocket* bsock_;
};
